package main

import (
	"context"
	"fmt"

	"ginmt/models/dao"
	"ginmt/wire"

	"github.com/mozillazg/go-pinyin"

	"strings"
)

func main() {
	db, err := wire.GormDb()

	if err != nil {
		panic(err)
	}

	query := dao.Use(db)
	queryCtx := query.WithContext(context.Background())

	regional := queryCtx.CspMtRegional

	mtRegionals, err := regional.Where(query.CspMtRegional.CityPyFirst.IsNull(), query.CspMtRegional.CityPy.IsNull()).Find()
	if err != nil {
		panic(err)
	}
	for i, _ := range mtRegionals {
		fmt.Println(mtRegionals[i])
		fmt.Println(pinyin.LazyConvert(mtRegionals[i].City, nil))
		transPinyin := strings.Join(pinyin.LazyConvert(mtRegionals[i].City, nil), " ")
		mtRegionals[i].CityPy = transPinyin
		mtRegionals[i].CityPyFirst = string(transPinyin[0])
		err := regional.Save(mtRegionals[i])
		if err != nil {
			fmt.Println("---->error", err)
		}
	}
}
